package com.red.controller.user;


import com.red.entity.Questions;
import com.red.result.Result;
import com.red.service.QuestionsService;
import com.red.service.RankingsService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/questions")
@ApiModel(value = "答题表接口")
public class QuestionsController {
    @Autowired
    private QuestionsService questionsService;
    @Autowired
    private RankingsService rankingsService;

    /**
     * 随机查询10个题目
     * @return
     */
    @GetMapping("/select")
    @ApiModelProperty("随机查询10个题目")
    public Result<List<Questions>> get_10_question(){

        List<Questions> list = questionsService.get_10_question();
        return Result.success(list);
    }

    /**
     * 新增题目
     * @param questions
     * @return
     */
    @PostMapping("/insert")
    @ApiModelProperty("新增题目")
    public Result insert(@RequestBody Questions questions){
        questionsService.insertQuestion(questions);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiModelProperty("批量删除")
    public Result deleteByIds(@PathVariable List<Long> ids){
        questionsService.deleteByIds(ids);
        return Result.success();
    }


    /**
     * 答题结果
     * @param score
     * @return
     */
    @PostMapping("/result/{score}")
    @ApiModelProperty("答题结果")
    public Result questionResult(@PathVariable int score){
        rankingsService.questionResult(score);
        return Result.success();
    }

}
